/**
 * Created by WT-SUN on 2017/4/18.
 */
$(function () {
    $('#disTb').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: true,
        sortOrder: true,
        fitColumns: true,
        pagination: true,
        toolbar: '#toolbar',
        url: ROOT_PATH + '/occupationalHealth/occDiseases/disTable.shtml',
        queryParams:{
            sort:'addTime',
            order:'desc'
        },
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {field: 'diseasesName', title: '职业病名称', width: 100, sortable: true},
            {field: 'diseasesTypeName', title: '职业病类型', width: 100, sortable: true},
            {field: 'diseasesCode', title: '职业病编码', width: 100},
            {field: 'userName', title: '登记人', width: 100, sortable: true},
            {field: 'addTime', title: '登记时间', width: 100},
            {field: 'deptName', title: '登记部门', width: 100}
        ]]
    });
    queryComboData();
    $('#btn_clear').on("click", function () {
        $('#queryForm').form('reset');
    });
    $('#btn_save').on("click", function () {
            var $selected = $('#disTb').datagrid('getSelections');
            if($selected.length==0){
                layer.alert("请选择职业病！");
                return;
            }
            WindowManager.closeLayer({
                returnValue: $selected
            });
    });
});

function queryComboData() {
    var code=CONSTANT.DictionaryTypeDefConstants.OHE_OCCDISEASES_TYPE;
    $.ajax({
        type: 'post',
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',
        data: {code: code},
        dataType: "json",
        success: function (result) {
            $('#diseasesType').combobox({
                data: result,
                valueField: 'id',
                textField: 'text',
                editable: false,
                panelHeight: '200',
            });
        }
    });
}
/**
 * 重新加载表格
 */
function reLoadData() {
    $('#disTb').datagrid('clearSelections');
    var queryParams = $('#queryForm').serializeJson();
    queryParams["sort"] = 'addTime';
    queryParams["order"] = 'desc';
    $('#disTb').datagrid('options').queryParams = queryParams;
    $("#disTb").datagrid('reload', ROOT_PATH + '/occupationalHealth/occDiseases/disTable.shtml');
}

